/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trim.gui.testing.models;

import java.util.List;
import javax.swing.table.AbstractTableModel;
import trim.common.inputdata.MaterialStock;

/**
 * Модель для отображения использованного количества иходного материала
 *
 * Created 21.12.2008 22:00:11
 * @author Саковнич Дмитрий
 */
public class UsedMaterialsTableModel extends AbstractTableModel implements IRowManipulationTableModel
{

  MaterialStock[] input;
  MaterialStock[] out;

  public UsedMaterialsTableModel(List<MaterialStock> input,List<MaterialStock> out)
  {
    this.input=input.toArray(new MaterialStock[0]);
    
    this.out=new MaterialStock[this.input.length];
    for(int i=0;i<this.input.length;i++)
    {
      this.out[i]=new MaterialStock(this.input[i].getMaterial(),0);
      for(MaterialStock mc:out)
      {
        if(mc.getMaterial().equals(this.out[i].getMaterial()))
        {
          this.out[i]=mc;
          break;
        }
      }
    }
  }

  public int getRowCount()
  {
    return input.length;
  }

  public int getColumnCount()
  {
    return 3;
  }

  public Object getValueAt(int rowIndex,int columnIndex)
  {
    MaterialStock in=input[rowIndex];
    MaterialStock o=out[rowIndex];
    switch(columnIndex)
    {
      case 0:
        return in.getMaterial().getLength();
      case 1:
        return in.getCount();
      case 2:
        return o.getCount();
    }
    return 0;
  }

  @Override
  public Class<?> getColumnClass(int columnIndex)
  {
    return Integer.class;
  }

  @Override
  public String getColumnName(int column)
  {
    switch(column)
    {
      case 0:
        return "Material";
      case 1:
        return "In";
      case 2:
        return "Res";
    }
    return super.getColumnName(column);
  }

  public void addRow()
  {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public void insertRow(int r)
  {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public void removeRow(int r)
  {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public Object getObject(int r)
  {
    return input[r].getMaterial();
  }
}
